package com.jt.tenant.widget;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * Created by Administrator on 2016/4/18.
 */
public class SearchEditView extends EditText {

    private OnChangeCallBack onChangeCallBack;

    private boolean isSet;

    public SearchEditView(Context context, AttributeSet attrs) {

        super(context, attrs);

        addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void afterTextChanged(Editable s) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if(!isSet && onChangeCallBack != null){

                    onChangeCallBack.onChange(s.toString());

                }

                isSet = false;

            }

        });

    }

    public void setText(String text){

        isSet = true;

        super.setText(text);

    }

    public void setOnChangeCallBack(OnChangeCallBack onChangeCallBack){

        this.onChangeCallBack = onChangeCallBack;

    }

    public interface OnChangeCallBack{

        void onChange(String text);

    }

}
